package com.cskaoyan.util;



import com.cskaoyan.bean.BaseRespVo;

import com.cskaoyan.exception.ValidationException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

/**

 * 创建日期: 2022/05/07 17:02
 *
 * @author shuyang
 */

// public class ValidationUtil {
//     public static void valid(BindingResult bindingResult) {
//         if (bindingResult.hasErrors()) {
//             FieldError fieldError = bindingResult.getFieldError();
//             Object rejectedValue = fieldError.getRejectedValue();
//             String field = fieldError.getField();
//             String defaultMessage = fieldError.getDefaultMessage();
//             String msg = "请求参数" + field + "传入的" + rejectedValue + "" + defaultMessage;
//             throw new ValidationException(msg);
//         }
//
//  * @author stone
//  * @date 2022/05/07 10:12
//  */
public class ValidationUtil {

    public static void valid(BindingResult bindingResult) throws ValidationException {

        if (bindingResult.hasErrors()) {
            // 拿到成员变量的错误
            FieldError fieldError = bindingResult.getFieldError();
            // 默认的消息
            String defaultMessage = fieldError.getDefaultMessage();

            throw new ValidationException(defaultMessage);
        }
    //'ValidationException()' in 'com.cskaoyan.exception.ValidationException' cannot be applied to '(java.lang.String)'

    }
}
